package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findById(Long id) {
        return userInfoMapper.selectById(id);
    }

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize) {
        //1.创建分页对象,设置分页参数
        Page<UserInfo> page = new Page<>(pageNum, pageSize);

        //2.若有其他条件的话创建条件对象
        //3.调用mapper的selectPage方法
        userInfoMapper.selectPage(page,null);

        //4.封装pageBeanVo且返回
        return new PageBeanVo(pageNum,pageSize,page.getTotal(), page.getRecords());
    }
}
